﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cloak.Reflection;

namespace Cloak.Mvp
{
	/// <summary>
	/// A mapping between view types and presenter references, using instances of <see cref="PresenterAttribute"/>
	/// </summary>
	public sealed class AttributedViewPresenterIndex : IViewPresenterIndex
	{
		/// <summary>
		/// Gets the presenters mapped to the specified view type via instances of <see cref="PresenterAttribute"/>
		/// </summary>
		/// <param name="viewType">The type of view associated with the presenters</param>
		/// <returns>The presenters mapped to the specified type</returns>
		public IEnumerable<IPresenterReference> GetPresenters(Type viewType)
		{
			return viewType.GetAttributes<PresenterAttribute>().Select(attribute => attribute.GetReference());
		}
	}
}